package com.code.generator.cn.controller;

import com.code.generator.cn.entity.CoderField;
import com.code.generator.cn.service.ICoderFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/field")
public class FieldController {

    @Autowired
    private ICoderFieldService coderFieldService;

    /**
     * 项目生成主页面
     * @return
     */
    @RequestMapping("/main")
    public ModelAndView getTables(HttpServletRequest request, @RequestParam String id){
        ModelAndView mv=new ModelAndView("/main/field");
        mv.addObject("id",id);
        return mv;
    }



    /**
     * 项目生成主页面
     * @return
     */
    @RequestMapping("/toUpdate")
    public ModelAndView toUpdate(HttpServletRequest request, @RequestParam String id){
        ModelAndView modelAndView =new ModelAndView("/field/update");
        modelAndView.addObject("obj",coderFieldService.getById(id));
        return modelAndView;
    }


    /**
     * 项目生成主页面
     * @return
     */
    @RequestMapping("/update")
    public Object toUpdate(HttpServletRequest request, @ModelAttribute CoderField coderField){
        coderFieldService.update(coderField);
        return null;
    }
}
